import QtQuick 2.0
import QtQml.Models 2.1

ListModel {
    id: demoModel
    ListElement {
        name: "Password"
        source: "SystemSetting/Password.qml"
        IconPath:"menu/menu_button_password"
        visible: true
        group: "System setting"
        groupIcon:"menu/menu_button_system_setting.png"
        groupOpen: true
    }
    ListElement {
        name: "Back light"
        source: "SystemSetting/Backlight.qml"
        IconPath:"menu/menu_button_backlight.png"
        visible: true
        group: "System setting"
        groupIcon:"status/usb_disk.png"
        groupOpen: true
    }
    ListElement {
        name: "Language"
        source: "SystemSetting/Language.qml"
        IconPath:"menu/menu_button_language.png"
        visible: true
        group: "System setting"
        groupIcon:"status/usb_disk.png"
        groupOpen: true
    }
    ListElement {
        name: "DataTime"
        source: "SystemSetting/DataTime.qml"
        IconPath:"menu/menu_button_date.png"
        visible: true
        group: "System setting"
        groupIcon:"status/usb_disk.png"
        groupOpen: true
    }

    ListElement {
        name: "DeviceInfo"
        source: "SystemSetting/DeviceInfo.qml"
        IconPath:"menu/menu_button_device_info.png"
        visible: true
        group: "System setting"
        groupIcon:"status/usb_disk.png"
        groupOpen: true
    }

    ListElement {
        name: "File List"
        source: "Files/Memorystatus.qml"
        IconPath:"menu/menu_button_logging_file_list.png"
        visible: true
        group: "Files"
        groupOpen: true
    }
    ListElement {
        name: "Images"
        source: "Files/Images.qml"
        IconPath:"menu/menu_button_date.png"
        visible: true
        group: "Files"
        groupOpen: true
    }
    ListElement {
        name: "ModbusMaster"
        source: "Communication/ModbusMaster.qml"
        IconPath:"menu/menu_button_modbus_master.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "IIoT"
        source: "Communication/IIoT.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }
    ListElement {
        name: "S4A"
        source: "Communication/S4A.qml"
        IconPath:"menu/menu_button_field-bus-rs485.png"
        visible: true
        group: "Communication"
        groupOpen: true
    }



//    ===============================================

    function getIconPath(section) {
        var ggpicon="menu/menu_button_location_setting.png"
        for (var i = 0; i < count; ++i) {
            var obj = get(i)
            if (obj["group"] === section) {
                if(obj["groupIcon"] === undefined){
                    return ggpicon
                }else{
                ggpicon = obj["groupIcon"]
                    return obj["groupIcon"]
                }
            }
        }
    }

    function updateSection(section, isOpen) {
        for (var i = 0; i < count; ++i) {
            var obj = get(i)
            if (obj["group"] === section) {
                setProperty(i, "groupOpen", isOpen)
            }
        }
    }
    function search(text) {
        var i = 0
        if (text.length <= 0) {
            for ( i = 0; i < count; ++i) {
                setProperty(i, "visible", true)
            }
        } else {
            var lowerText = String(text).toLowerCase()
            for (i = 0; i < count; ++i) {
                var obj = get(i)
                if (qsTr(obj["name"]).toLowerCase().indexOf(lowerText) >= 0) {
                    setProperty(i, "visible", true)                    
                    setProperty(i, "groupOpen", true)
                } else {
                    setProperty(i, "visible", false)
                }
            }
        }
    }
}
